﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.Core.ServiceBus
{
    /// <summary>
    /// Service Bus Message Bag
    /// </summary>
    /// <remarks>
    /// This class is used to carry business object onto the service bus infrastructure...
    /// </remarks>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    [DataContract(Namespace = "www.grayparrot.com")]
    public abstract class ServiceBusMessageBagBase<T, R> 
        where T : class, new()
        where R : class, new()
    {
        private Guid m_correlationID = Guid.Empty;
        private string m_messageName = string.Empty;
        //private T m_body = null;

        [DataMember]
        public Guid MessageID { get; set; }

        [DataMember]
        public DateTime Timestamp { get; set; }

        [DataMember]
        public string MessageName
        {
            get { return m_messageName; }
            set { m_messageName = value; }
        }

        [DataMember]
        public Guid CorrelationID
        {
            get { return m_correlationID; }
            set { m_correlationID = value; }
        }

        [DataMember]
        public T Body { get; set; }

        public ServiceBusMessageBagBase()
        {

        }

        public ServiceBusMessageBagBase(string messageName)
        {
            this.CorrelationID = Guid.NewGuid();
            this.MessageID = Guid.NewGuid();
            this.MessageName = messageName;
            this.Timestamp = DateTime.Now;
            Body = new T();
        }

        /// <summary>
        /// Converts To the specific type the implementation of the service bus needs for carry it...
        /// </summary>
        /// <returns>a service bus implementation specific object if success, null otherwise</returns>
        public abstract R ToBrokeredMessage();
    }
}
